package com.example.moonshine.zxing.Util;

import com.example.moonshine.zxing.Data.ReturnPostData;
import com.example.moonshine.zxing.Data.ReturnStatusData;
import com.example.moonshine.zxing.Data.ScopeData;
import com.google.gson.Gson;

import okhttp3.FormBody;
import okhttp3.MediaType;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;

/**
 * Created by moonshine on 2018/2/1.
 */

public class SpostHttp {

//    String urldl="http://123.249.28.108:8081/element/audit-di";
//    String alUrl = "http://123.249.28.108:8081/element/audit-al";
//    String path1 = "http://192.168.28.7:8080/element/audit-pa";
    public String posthttpresult(String al_id,String al_weight,String url, String al_type,String Creator) {

        String SpostStatus = null;
        //okhttp Post请求传输Json数据
        Gson gson =new Gson();
        OkHttpClient client = new OkHttpClient();
        MediaType JSON = MediaType.parse("application/json; charset=utf-8");
        FormBody body = new FormBody.Builder()
                .add("alId",al_id)
                .add("alWeight",al_weight)
                .add("alType",al_type)
                .add("creator",Creator)
                .build();
        Request request = new Request.Builder()
                .url(url)
                .post(body)
                .build();

        try {
            Response response = client.newCall(request).execute();

            //获取后台传输的额status状态码
            String result = response.body().string();


            //将接收到的JSON数据放到实体类里
            ReturnStatusData returnStatusData= gson.fromJson(result,ReturnStatusData.class);
            //定义一个参数来获取状态码
            SpostStatus = returnStatusData.getStatus();
        }catch (Exception e){
            e.printStackTrace();
        }
        return SpostStatus;
    }

    public String Dposthttpresult(String diluent_id,String url,String Creator) {

        String SpostStatus = null;
        //okhttp Post请求传输Json数据
        Gson gson =new Gson();
        OkHttpClient client = new OkHttpClient();
        MediaType JSON = MediaType.parse("application/json; charset=utf-8");
        FormBody body = new FormBody.Builder()
                .add("diluentId",diluent_id)
                .add("creator",Creator)
                .build();
        Request request = new Request.Builder()
                .url(url)
                .post(body)
                .build();

        try {
            Response response = client.newCall(request).execute();

            //获取后台传输的额status状态码
            String result = response.body().string();


            //将接收到的JSON数据放到实体类里
            ReturnStatusData returnStatusData= gson.fromJson(result,ReturnStatusData.class);
            //定义一个参数来获取状态码
            SpostStatus = returnStatusData.getStatus();
        }catch (Exception e){
            e.printStackTrace();
        }
        return SpostStatus;
    }

    public String Pposthttpresult(String paint_id,String paint_weight,String url, String paint_type,String Creator) {

        String SpostStatus = null;
        //okhttp Post请求传输Json数据
        Gson gson =new Gson();
        OkHttpClient client = new OkHttpClient();
        MediaType JSON = MediaType.parse("application/json; charset=utf-8");
        FormBody body = new FormBody.Builder()
                .add("paintId",paint_id)
                .add("paintWeight",paint_weight)
                .add("pType",paint_type)
                .add("creator",Creator)
                .build();
        Request request = new Request.Builder()
                .url(url)
                .post(body)
                .build();

        try {
            Response response = client.newCall(request).execute();

            //获取后台传输的额status状态码
            String result = response.body().string();


            //将接收到的JSON数据放到实体类里
            ReturnStatusData returnStatusData= gson.fromJson(result,ReturnStatusData.class);
            //定义一个参数来获取状态码
            SpostStatus = returnStatusData.getStatus();
        }catch (Exception e){
            e.printStackTrace();
        }
        return SpostStatus;
    }
}

